/*!
 * \file GapGenerator.h
 * \brief Generator for GAP state machine in Serving Gateway
 */

#ifndef SGW_GAP_GENERATOR_H
#define SGW_GAP_GENERATOR_H

#include "Generator.h"
#include "StateBase.h"
#include "GapGlobals.h"
#include "Timer.h"

namespace tsc
{
namespace sgw
{

/**
 * Generator implementation for GAP protocol in Serving Gateway.
 * One GapGenerator corresponds to one Media Gateway
 */
class GapGenerator : public common::Generator
{
public:

	/**
	 * Creates new GapGenerator for handling new signaling connection with
	 * Media Gateway
	 *
	 */
	GapGenerator(common::GeneratorEnvironment& ge,
			     uint32_t mgwId);

	virtual ~GapGenerator();

	static bool findGenerator(uint32_t mgwId, GapGenerator*& generator);

    uint32_t getMgwId() const;

    /**
     * Checks if transmission to MGW associated with this generator
     * is possible
     */
    bool txEnabled() const;

    void startT823(unsigned long valueMs = T_823_VALUE);
    void cancelT823();

    void startT8221(unsigned long valueMs = T_8221_VALUE);
    void cancelT8221();

    const ProtocolsCommon::IpAddress* getMgwIpAddress() const;
    void setMgwIpAddress(ProtocolsCommon::IpAddress* mpMgwIpAddress);

private:

    void assignGeneratorId();

	/**
	 * Timer controlling interval of sending of EchoReq
	 */
	common::Timer* mpT823;

	/**
	 * Timer controlling waiting for EchoResp
	 */
	common::Timer* mpT8221;

    ProtocolsCommon::IpAddress* mpMgwIpAddress;

	static uint32_t msGeneratorId;
};

} // namespace sgw
} // namespace tsc

#endif // SGW_GAP_GENERATOR_H
